#include <stdio.h>
#include <iostream>

#ifndef Uint8 
#define Uint8 unsigned char
#endif

#ifndef SDL_Surface 
#define SDL_Surface unsigned int
#endif

using namespace std;

struct Nodo
{
	unsigned int ID;
	unsigned int *surfaceGen;
	unsigned int *surfacePers;

	unsigned int coord_x;
	unsigned int coord_y;

	Nodo* prox;
	Nodo* prev;
};

struct Lista
{
	Nodo* primero;
};

struct Iterador
{
	Nodo* actual;
};

extern "C" void agregar_item_ordenado(Lista* la_lista, SDL_Surface* surfacePers, SDL_Surface* surfaceGen, unsigned int x, unsigned int y, unsigned int ID);
extern "C" void borrar(Lista* la_lista, unsigned int x, unsigned int y);
extern "C"  Lista* constructor_lista();
extern "C" void inicializar_nodo(Nodo* nuevo, SDL_Surface *surfacePers, SDL_Surface *surfaceGen, unsigned int x, unsigned int y, unsigned int ID);
extern "C" void liberar_lista(Lista* l);

extern "C" Iterador* constructor_iterador(Lista *lista);
extern "C" bool hay_proximo(Iterador *iter);
extern "C" Nodo* item(Iterador *iter);
extern "C" void liberar_iterador(Iterador *iter);
extern "C" void proximo(Iterador *iter);

int main()
{
	//crear lista vacia
	Lista *lista;
	lista = constructor_lista();
	cout << "Lista" << endl;	
	cout << lista->primero << endl;		

	//crear nodo en la lista
	unsigned int Id = 1;
	unsigned int *surfaceGen = NULL;
	unsigned int *surfacePers = NULL;
	unsigned int x = 100;
	unsigned int y = 20;
	
	//Agrego nodo
	agregar_item_ordenado(lista, surfacePers,surfaceGen, x, y, Id);
	
	unsigned int Id2 = 4;
	unsigned int *surfaceGen2 = NULL;
	unsigned int *surfacePers2 = NULL;
	unsigned int x2 = 100;
	unsigned int y2 = 80;
	
	//Agrego nodo
	agregar_item_ordenado(lista, surfacePers2,surfaceGen2, x2, y2, Id2);
	
	unsigned int Id3 = 11;
	unsigned int *surfaceGen3 = NULL;
	unsigned int *surfacePers3 = NULL;
	unsigned int x3 = 100;
	unsigned int y3 = 80;
	
	agregar_item_ordenado(lista, surfacePers3,surfaceGen3, x3, y3, Id3);

	//Agrego nodo
	unsigned int Id4 = 11;
	unsigned int *surfaceGen4 = NULL;
	unsigned int *surfacePers4 = NULL;

	unsigned int x4 = 100;
	unsigned int y4 = 24;

	agregar_item_ordenado(lista, surfacePers4,surfaceGen4, x4, y4, Id4);

	cout << "Prev_Primero:" << lista->primero->prev << endl;
	cout << "Primero:" << lista->primero << endl;
	cout << "Prox_Primero:" << lista->primero->prox << endl;
	cout << " ";
	cout << "Prev_Segundo:" << lista->primero->prox->prev << endl;
	cout << "Segundo:" << lista->primero->prox << endl;
	cout << "Prox_Segundo:" << lista->primero->prox->prox << endl;
	cout << " ";
	cout << "Prev_Tercero:" << lista->primero->prox->prox->prev << endl;
	cout << "Tercero:" << lista->primero->prox->prox << endl;
	cout << "Prox_Tercero:" << lista->primero->prox->prox->prox << endl;
	cout << " ";
	cout << "Prev_Cuarto:" << lista->primero->prox->prox->prox->prev << endl;
	cout << "Cuarto:" << lista->primero->prox->prox->prox << endl;
	cout << "Prox_Cuarto:" << lista->primero->prox->prox->prox->prox << endl;
	cout << " ";
	
	cout << "Crear iterador" << endl;
	Iterador *iter;
	iter = constructor_iterador(lista);
	cout << iter->actual << endl;
	
	item(iter);
	cout << "item" << iter->actual << endl;
	
	cout << "hay proximo" << endl;
	int res;	
	res = hay_proximo(iter);
	cout << res << endl;

	cout << "proximo" << endl;
	proximo(iter);
	cout << iter->actual << endl;
	cout << "n"<< endl;

	cout << "hay proximo" << endl;
	bool res1;
	res1 = hay_proximo(iter);
	cout << res1 << endl;
	cout << "/n"<< endl;
	cout << "proximo" << endl;
	proximo(iter);
	cout << iter->actual << endl;
	cout << "/n"<< endl;
	cout << "hay proximo" << endl;
	bool res2;
	res2 = hay_proximo(iter);
	cout << res2 << endl;
	cout << "/n"<< endl;
	cout << "proximo" << endl;
	proximo(iter);
	cout << iter->actual << endl;
	cout << "/n"<< endl;
	cout << "hay proximo" << endl;
	bool res3;	
	res3 = hay_proximo(iter);
	cout << res3 << endl;
	
	
	cout << "liberar" << endl;
	liberar_iterador(iter)	;	
	cout << iter->actual << endl;

	
	return(0);

}

